﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Corona.TagToolkit;

namespace Corona.TagToolkit
{
    public sealed class Tag
    {

        private string name;
        private string value;

        /// <summary>
        /// 标签的种类，对应于xml中的结点的name属性
        /// </summary>

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        /// <summary>
        /// 标签的值，对应于xml中的结点的InnerText
        /// </summary>

        public string Value
        {
            get { return this.value; }
            set { this.value = value; }
        }
        public Tag() { }

        public Tag(string name, string value)
        {
            this.name = name;
            this.value = value;
        }

        /// <summary>
        /// 创建空名Tag
        /// </summary>
        /// <param name="value"></param>
        public Tag(string value)
        {
            this.name = null;
            this.value = value;
        }

        public static implicit operator Corona.TagContract.Tag(Corona.TagToolkit.Tag tag)
        {
            Corona.TagContract.Tag romateTag = new Corona.TagContract.Tag();
            romateTag.Name = tag.Name;
            romateTag.Value = tag.Value;
            return romateTag;
        }


        /// <summary>
        /// 已重载，判值
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            Tag tag = obj as Tag;
            if (tag == null)
                return false;
            else
                return this.name == tag.name && this.value == tag.value;
        }

        public override int GetHashCode()
        {
            return name.GetHashCode() ^ value.GetHashCode();
        }

        public override string ToString()
        {
            return "Name = \"" + Name + "\",Value = \"" + Value + "\"";
        }
    }

}
